home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / msoftapp.zip / PRECOMP.TXT < prev    next >
Text File  |  1993-04-15  |  3KB  |  48 lines

  1. Precompiled Headers
  2. Precompiled headers are a means of greatly speeding compile time by 
  3. compiling header files only once into a precompiled header file (PCH) 
  4. and thereafter using the precompiled header for each build. Visual C++ 
  5. provides two different ways to implement precompiled headers. You 
  6. can use the new simplified method (/YX), or you can use the more flexible 
  7. method (/Yc and /Yu), for more control and for mixed-
  8. language (C and C++) source files. These choices can be made from the 
  9. Visual WorkBench's Option Project Compiler Precompiled Headers dialog. 
  10.  
  11. Due to space restrictions, only the simplified method is discussed here.
  12. When applied to a single source file, /YX simply compiles all 
  13. preprocessor directives (such as #include), from the start of the file 
  14. to the start of C or C++ code, into a file named MSVC.PCH (which can be 
  15. renamed using /Fp). In Visual Workbench you select the Automatic Use of 
  16. Precompiled Headers compiler option to enable /YX.
  17. When applied to multiple source files, /YX will first create a 
  18. precompiled header file using the #includes from the first file.  On 
  19. each subsequent source file it will examine the order of the #include 
  20. files and check that they match the order of the files in the 
  21. precompiled header file.  If they match directly, the precompiled 
  22. header file is used as is.  This is the most efficient way to use /YX.  
  23. If a subset of the #include files are in common, the compiler 
  24. automatically pares down the precompiled header file to only represent 
  25. the common subset of #include files and uses that.  Generally, after 
  26. comparing two source files a usable common subset will emerge.  If no 
  27. #include files are found in common, the PCH file is not used and 
  28. compilation proceeds.
  29.  
  30. The advantage of using Automatic Precompiled Headers is that it will 
  31. quietly work to build and use an efficient precompiled header file on 
  32. any collection of source files.  However, you can achieve better build 
  33. times if you are willing to edit your source files.  You will get the 
  34. most efficient build times by listing the same include statements in 
  35. the same order in all project source files. If you don't do this for 
  36. all include statements, at least do it for all include files you want 
  37. precompiled and put them first.  Generally, you should include all the 
  38. big include files that you use, like WINDOWS.H or AFXWIN.H, in this subset.
  39. Another useful technique is to place all these large include files that 
  40. are unlikely to change into their own header file and then include this 
  41. master include file at the beginning of each source file followed by 
  42. any #include statements that are needed locally.  This gives you an 
  43. easy to maintain file structure that works very well with Auto PCH.  
  44. This is exactly what AppWizard does with the file STDAFX.H that it 
  45. includes at the beginning of each source file.
  46.  
  47.  
  48.